 var id = getvl("id");
 var currentPage=1;
 $(function(){
 	   if(id!=null){
 	   	  selectGoodsList2(id);
 	  	$("#quanbu").attr("href","34.0.0sell_dingdan.html?id="+id);
 	   	$("#daifahuo").attr("href","34.2.0sell_dingdan_daifahuo.html?id="+id);
 	   $("#daifukuan").attr("href","34.1.0sell_dingdan_daifukuan.html?id="+id);
 	   $("#daishouhuo").attr("href","34.3.0sell_dingdan_daishouhuo.html?id="+id);
 	   $("#daiqueren").attr("href","34.4.0sell_dingdan_daiqueren.html?id="+id);
 	   }else{
 	    	alert("登录异常...");
 	   }
 });
 
  var ss=0;
function  selectGoodsList2(){ 
	if(currentPage==1 || ss!=0){
           $.ajax({
             url: urlcore + "/api/order/WXselect?current="+currentPage+"&userId="+id+"&status=2&types=2",
            type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
				if(data.success == true) {
					ss=data.data.length;
					$.each(data.data,function(y,n) {
						   if(n.goodsCarList!=null){
						  var zhuantai="";
						    if(n.status==0){
						    	zhuantai="未付款";
						    }else if(n.status==1){
						    	if(n.tradeStatus==0){
						    		zhuantai="待发货";
						    	}else if(n.tradeStatus==1){
						    		zhuantai="待收货";
						    	}
						    }else if(n.status==8){
						    	zhuantai="申请退款中";
						    }else if(n.status==9){
						    	zhuantai="退款失败";
						    }else if(n.status==10){
						    	zhuantai="已完成";
						    }
						
			var quanbuleirong=
			'<div class="detail_goods clearfix">'+
			'    <h3>买家:'+n.user.userName+'<span>'+zhuantai+'</span></h3>';
    	             
	          $.each(n.goodsCarList, function(k,m) {
	          	 quanbuleirong+='<div class="clearfix tuwen">';
	          	 
	          	    if(n.status==0){
	      quanbuleirong+='<a href="35.0.0sell_dingdan_daifukuan_detail.html?id='+n.id+'">';
	          	    }else if(n.status==1){
						 if(n.tradeStatus==0){
		 quanbuleirong+='<a href="36.0.0sell_dingdan_daifahuo_detail.html?id='+n.id+'">';
						  }else if(n.tradeStatus==1){
		 quanbuleirong+='<a href="37.0.0sell_dingdan_daishouhuo_detail.html?id='+n.id+'">';
						   }
	          	    }else if(n.status==8){
		   quanbuleirong+='<a href="39.0.0sell_dingdan_daituikuan_detail.html?id='+n.id+'">';
						    }else if(n.status==9){
			  quanbuleirong+='<a href="38.0.0sell_dingdan_yiwancheng_detail.html?id='+n.id+'">';
						    }else if(n.status==10){
			  quanbuleirong+='<a href="39.3.0sell_dingdan_daituikuan_detail_tuikuan_chenggong.html?id='+n.id+'">';
						    }
    	             quanbuleirong+='<div class="tuwen-img fl">'+
	          	 '<img onerror="errorImg(this)" src="'+m.goods.coverUrl+'" width="75" height="75">'+
	        '</div>'+
	        '<div class="tuwen-wenzi">'+
	            '<h5 class="wuye_h01">'+m.goods.goodsTitle+'</h5>'+
	           '<div class="wuye_div01">产品均有保障</div>'+
	        '</div>'+
        '</a>'+
    '</div>';
              if(m.myStockList!=null){
    	  $.each(m.myStockList, function(q,w) {
           	   quanbuleirong+='<div class="dingdan_fenlei clearfix">'+
    	  '<ul class="fl">';
    		if(w.colour!=null){
    quanbuleirong+='<li>颜色：<span>'+w.colour.colourName+'</span></li>';
    		}
    		
    		if(w.size!=null){
    quanbuleirong+='<li>尺码：<span>'+w.size.sizeName+'</span></li>';			
    		}
    			if(m.packRate!=null){
    quanbuleirong+='<li>单价：<span>'+m.packRate+'元/件</span></li>';
    		}

    	   
    	     quanbuleirong+='</ul>'+
    	'<div class="fr">';
    	   
    	    /*  if(n.goodsNumber>=m.tradeNumber){*/
    	      	quanbuleirong+='<h5>'+(m.packRate*w.saleNum)+'元</h5>'+
    		'<h6>'+w.saleNum+'件</h6>';
    	   /*   }else{
    	     quanbuleirong+='<h5>'+m.goods.packPrice+'元</h5>'+
    		'<h6>'+n.goodsNumber+'件</h6>';
    	      }*/
    	quanbuleirong+='</div>'+
              '</div>';
           });
          }
           
             });
           
            	     if(n.status==0){
	 quanbuleirong+= '<div class="sell_dingdan">'+
'    	<div class="sell_dingdan_price clearfix">'+
'    		<h5>共<em>'+n.goodsNumber+'</em>件<i>(含运费'+n.freightMoney+'元)</i></h5>'+
'    		<span>&yen;'+n.payMoney+'</span>'+
'    	</div>'+
'    </div>'+
' <div class="sell_dingdan">'+
'    	<div class="sell_dingdan_button">'+
'    		<a href="javascript:void(0);" onclick="goupdate(this)"   id="'+n.orderNumber+'" class="sell_dingdan_huang P-xiugai">修改价格</a>'+
'<input type="hidden" value="'+n.freightMoney+'" id="mails">'+
'<input type="hidden" value="'+n.payMoney+'" id="Ordertotalprice">'+ 
'    	</div>'+
'    </div>'+
'</div>';
            	     }else if(n.status==1){
						    	if(n.tradeStatus==0){
	 quanbuleirong+= '<div class="sell_dingdan">'+
'    	<div class="sell_dingdan_price clearfix">'+
'    		<h5>共<em>'+n.goodsNumber+'</em>件<i>(含运费'+n.freightMoney+'元)</i></h5>'+
'    		<span>&yen;'+n.payMoney+'</span>'+
'    	</div>'+
'    </div>'+
'<div class="sell_dingdan_button">'+
'    		<a href="javascript:void(0);" id="'+n.orderNumber+'"  onclick="tuifeis(this)" class="P-tuifei">退费</a>'+
'<input type="hidden" value="'+n.freightMoney+'" id="mails">'+
'<input type="hidden" value="'+n.payMoney+'" id="Ordertotalprice">'+ 
'    		<a href="36.1.0sell_dingdan_daifahuo_fahuotianxie.html?id='+n.id+'" class="sell_dingdan_huang">发货</a>'+
'    	</div>'+
'    </div>'+
'</div>';	    		
		       }else if(n.tradeStatus==1){
					 quanbuleirong+= '<div class="sell_dingdan">'+
'    	<div class="sell_dingdan_price clearfix">'+
'    		<h5>共<em>'+n.goodsNumber+'</em>件<i>(含运费'+n.freightMoney+'元)</i></h5>'+
'    		<span>&yen;'+n.payMoney+'</span>'+
'    	</div>'+
'    </div>'+
					 '<div class="sell_dingdan_button">'+
'    		<a href="javascript:void(0);" id="'+n.orderNumber+'" onclick="tuifeis(this)" class="P-tuifei">退费</a>'+
'<input type="hidden" value="'+n.freightMoney+'" id="mails">'+
'<input type="hidden" value="'+n.payMoney+'" id="Ordertotalprice">'+ 
'    		<a href="36.1.0sell_dingdan_daifahuo_fahuotianxie.html?ids='+n.id+'">修改物流</a>'+
'    		<a href="../buy/12.8.5buy_dingdan_wuliu.html?orderNumber='+n.id+'">订单跟踪</a>'+
'    		<a href="javascript:void(0);" class="sell_dingdan_huang">提醒收货</a>'+
'    	</div>'+
'    </div>'+
'</div>';
                 $("#jiness").html(n.payMoney);
                 $("#youfeis").html(n.freightMoney);
						    }
						    	}else if(n.status==8){
				 quanbuleirong+= '<div class="sell_dingdan">'+
'    	<div class="sell_dingdan_price clearfix">'+
'    		<h5>共<em>'+n.goodsNumber+'</em>件<i>(含运费'+n.freightMoney+'元)</i></h5>'+
'    		<span>&yen;'+n.payMoney+'</span>'+
'    	</div>'+
'    </div>'+
				'<div class="sell_dingdan_button">'+
'    		<a href="javascript:void(0);" class="sell_dingdan_huang">同意退款</a>'+
'    	</div>'+
'    </div>'+
'<div class="sell_dingdan_button">'+
'    		<a href="javascript:void(0);" class="sell_dingdan_huang">拒绝退款</a>'+
'    	</div>'+
'    </div>'+
'</div>';
						    }else{
						    	
	 quanbuleirong+= '<div class="sell_dingdan">'+
'    	<div class="sell_dingdan_price clearfix">'+
'    		<h5>共<em>'+n.goodsNumber+'</em>件<i>(含运费'+n.freightMoney+'元)</i></h5>'+
'    		<span>&yen;'+n.payMoney+'</span>'+
'    	</div>'+
'    </div>';
						    }
						$("#quanbuleirong").append(quanbuleirong);
				 }		
			});
			
			      $(function(){
			      	  $(".P-tuifei").on('click',function(){
        $("body").append("<div id='mask'></div>");
        $(".sell-xiugai2").show();
    })
    //点击关闭
    $(".show2_anniu span").on('click',function(){
        $(".sell-xiugai2").hide();
        $("#mask").remove();
    }) 
    
    
    // 修改价格
    // 弹出
    $(".P-xiugai").on('click',function(){
        $("body").append("<div id='mask'></div>");
        $(".sell-xiugai1").show();
    })
    //点击关闭
    $(".show2_anniu span").on('click',function(){
        $(".sell-xiugai1").hide();
        $("#mask").remove();
    }) 
			      });
			
					
				} else if(data.code == 'OVERTIME') {
					var thisUrl = window.location.href;
					alert(thisUrl);
					if(thisUrl.indexOf('1.0.0denglu.html') <= -1) {
						top.window.location.href = "1.0.0denglu.html";
					}

				} else {
					if(data.msg != '空数据') {
						alert(data.msg)
					} else {
						$('#thiscount').text(0);
					}
				}

			},
			error: function() {
				alert("error");
			}
		});
		}
	}
	
//取消订单

function bianhaos(te){
	$("#biaohaos").val("");
	$("#biaohaos").val(te);
}

function  querenquxiao(){
	 var biaohaos=$("#biaohaos").val();  
	 if(biaohaos==''){
	 	//alert("出现异常");
	 }else{
   	  $.ajax({
      url: urlcore+"/api/order/cancelOrder?orderNumber="+biaohaos,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
				if(data.success == true) {
					selectGoodsList2();
				//  alert("取消成功");
				}
		/*console.log(goodslist);*/
			},
			error: function() {
				alert("error");
			}
		});
}
}


function tuifeiqueren(){
	   var tuifei=$("#tuifeiyong").val();
    //  alert("退费待确认"+tuifei);	
	
}




function goupdate(te){
	   $("#ordernaber").val("");
  var tuifeioderid=$(te).attr("id");
   $("#ordernaber").val(tuifeioderid);
   var yuns=$(te).next().val();
   var Ordertotalprice=$(te).next().next().val();
   var zongjia=parseFloat(yuns)+parseFloat(Ordertotalprice);
   $("#shishoujineorid").html(zongjia);
   $("#yunfeioid").val(yuns);
   $("#huokaunorid").val(Ordertotalprice);
}


function tuifeis(te){  //退费的
	$("#ordermoylie").html("");
   $("#yuns").html("");
   var yuns=$(te).next().val();
   $("#tuifeioderid").val("");
  var tuifeioderid=$(te).attr("id");
   $("#tuifeioderid").val(tuifeioderid);
   var Ordertotalprice=$(te).next().next().val();
   $("#ordermoylie").html(Ordertotalprice);
   $("#yuns").html(yuns);
}


function xiugaimaliy(){  //修改价格
   var	huokaunorid=parseFloat($("#huokaunorid").val());
  var yunfeioid=parseFloat($("#yunfeioid").val());
   var ordernaber=$("#ordernaber").val();
	if(ordernaber!="" && uuuuid!="" ){
   	  $.ajax({
      url: urlcore+"/api/order/updatePrice2?orderNumber="+ordernaber+"&userid="+uuuuid+"&payMoney="+huokaunorid+"&freightMoney="+yunfeioid,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
				if(data.success == true) {
				var lujing=window.location.href;
				window.location.href=lujing;
					
				}
		/*console.log(goodslist);*/
			},
			error: function() {
				alert("error");
			}
		});
		
	}
}

function tuifei(){
	var tuifei=parseFloat($("#tuifeijinge").val());
	var tuifeioderid=$("#tuifeioderid").val();
	var tui=$("#yuns").html();

	if(tuifeioderid!=null&& tuifeioderid!=''){
		//alert("1")
		if(tuifei>0){
			//alert("12323")
if(uuuuid!=""){
	//alert("12323...")
   	  $.ajax({
      url: urlcore+"/api/order/updatePrice2?orderNumber="+tuifeioderid+"&userid="+uuuuid+"&payMoney="+tuifei+"&freightMoney="+tui,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
				if(data.success == true) {
			/*		var lujing=window.location.href;
				window.location.href=lujing;*/
				window.location.reload(); 
				}
			},
			error: function() {
				alert("error");
			}
		});
			}
	}
	}
	
	
}
